home *** CD-ROM | disk | FTP | other *** search
Wrap
/* $VER: CfgAutoReply.thor 1.1 (28.08.96) by Neil Bothwick */ /* Config editor for AutoReply.br, an arexx script for */ /* Thor to generate an event in reply to an email. */ options results /* :Make sure CfgAutoReply is being run from Thor */ thorport = address() if left(thorport,5) ~= 'THOR.' then do say 'CfgAutoReply.thor must be run from Thor' exit 10 end ;; /* :Ensure rexxsupport and bbsread libraries are loaded */ if ~show('L','rexxsupport.library') then call addlib('rexxsupport.library',0,-30) if ~show('p', 'BBSREAD') then do address command 'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead' 'WaitForPort BBSREAD' end ;; /* :Set parameters */ Changed = 0 CfgFile = 'ENV:THOR/AutoReply.cfg' FieldsMenu = '"Name" "System" "Conference" "Reply Text" "Subject" "Quote Message" "Quote String" "Signature File" "Header File" "Footer File"' FieldNames = '"CONFIG" "SYSTEM" "CONFERENCE" "TEXTFILE" "SUBJECT" "QUOTEMSG" "QUOTESTR" "SIGFILE" "HEADFILE" "FOOTFILE"' MainMenu = '"Add config" "Edit config" "Delete config" " " "Use" "Save" " " "Help"' MainTemplate = 'LINE/M' MenuTemplate = 'MENU/M' NameTemplate = 'NAME/M' address(bbsread) drop Menu. Fields. READARGS MainTemplate Menu cmdline MainMenu if RC > 0 then call ExitMsg(BBSREAD.LASTERROR) READARGS MenuTemplate Fields cmdline FieldsMenu if RC > 0 then call ExitMsg(BBSREAD.LASTERROR) READARGS NameTemplate Fields cmdline FieldNames if RC > 0 then call ExitMsg(BBSREAD.LASTERROR) ;; /* :Read config file */ address(thorport) CfgFileSize = word(statef(CfgFile),2) BytesRead = 0 drop Config. CfgNo = 0 if ~open(infile,CfgFile,'r') then do REQUESTNOTIFY '"Failed to open an existing configuration file"' '" OK "' Config.Count = 0 end else do /* Open progress window */ OPENPROGRESS title '"CfgAutoReply.thor"' PT '"Reading configuration"' if RC > 0 then call ExitMsg(THOR.LASTERROR) ProgWin = result address(bbsread) do until eof(infile) nextln = readln(infile) BytesRead = BytesRead + length(nextln) + 1 if upper(word(nextln,1)) = 'CONFIG' then do CfgNo = CfgNo + 1 drop Args. template = 'NAME/A,VALUE/A' READARGS template Args CMDLINE nextln if RC > 0 then call ExitMsg('Incorrect line in config:\n'||nextline) Config.CfgNo = Args.Value do until Args.Name = 'ENDCONFIG' if eof(infile) then call ExitMsg('End of config reached without ENDCONFIG') nextln = readln(infile) BytesRead = BytesRead + length(nextln) + 1 drop Args. Config.CfgNo. template = 'NAME/A,VALUE' READARGS template Args CMDLINE nextln if RC > 0 then call ExitMsg('Incorrect line in config:\n'||nextline) if Args.Name = 'CONFIG' then Config.CfgNo = Args.Value else do i = 2 to Fields.Name.Count if Args.Name = Fields.Name.i then do interpret 'Config.CfgNo.'fields.Name.i' = Args.Value' iterate end end end /* Update progress bar */ address(thorport) UPDATEPROGRESS req ProgWin current BytesRead*100%CfgFileSize address(bbsread) end end call close(infile) Config.Count = CfgNo address(thorport) CLOSEPROGRESS req ProgWin end ;; /* :Main loop */ address(thorport) do until pos(upper(Choice),'SAVEUSE') > 0 Choice = ShowMain() select when Choice = Menu.Line.1 then call AddCfg when Choice = Menu.Line.2 then call EditCfg(0) when Choice = Menu.Line.3 then call DeleteCfg when Choice = 'Use' then call UseCfg when Choice = 'Save' then call SaveCfg when Choice = 'Help' then call ShowHelp otherwise leave end end ;; /* :Exit, after checking if config should be saved */ if Changed = 1 then REQUESTNOTIFY '"You have changed the configuration.\nDo you want to save it before exiting?"' '"_Save|_Use|E_xit"' if RC = 30 then call ExitMsg(THOR.LASTERROR) select when result = 1 then call SaveCfg when result = 2 then call UseCfg otherwise nop end exit ;; /* ========== Procedures ========== */ /* :Exit with error message */ ExitMsg: address(thorport) parse arg errmsg REQUESTNOTIFY '"'errmsg'"' '"Abort"' exit ;; /* :Show main menu */ ShowMain: address(thorport) do until result ~= ' ' drop PICKED. REQUESTLIST instem Menu.LINE TITLE '"CfgAutoReply.thor "' SIZEGADGET end if RC = 5 then return 'QUIT' if RC > 0 then call ExitMsg(THOR.LASTERROR) return result ;; /* :Edit a configuration */ EditCfg: arg CfgNo OldChanged = Changed /* Select config to edit if not specified */ if CfgNo = 0 then do if Config.Count = 0 then do /* Return if no configs defined */ REQUESTNOTIFY '"You need to create a configuration\nitem before you can edit it ;-)"' '" OK "' return 5 end REQUESTLIST instem Config title '"Choose config to edit"' if RC = 5 then return 5 if RC > 0 then call ExitMsg(THOR.LASTERROR) EditCfg = result do i = 1 to Config.Count if Config.i = EditCfg then leave end CfgNo = i end /* Copy values to temporary variable for editing */ drop EditTemp. EditTemp.Config = Config.CfgNo do i = 2 to Fields.Name.Count if symbol('Config.CfgNo.'Fields.Name.i) = 'VAR' then interpret 'EditTemp.'Fields.Name.i' = Config.CfgNo.'Fields.Name.i else interpret 'EditTemp.'Fields.Name.i' = ""' end /* Display edit menu */ do forever /* Set up menu */ drop EditMenu. EditMenu.Count = Fields.Name.Count + 4 do i = 1 to Fields.Name.Count interpret 'EditMenu.i = left(Fields.Menu.i||": ",22)||EditTemp.'Fields.Name.i end interpret 'EditMenu.'EditMenu.Count-3' = ""' interpret 'EditMenu.'EditMenu.Count-2' = "Accept"' interpret 'EditMenu.'EditMenu.Count-1' = ""' interpret 'EditMenu.'EditMenu.Count' = "Help"' /* Select field to edit */ REQUESTLIST instem EditMenu title '"Choose a field to edit"' if RC = 5 then do Changed = OldChanged return 5 end if RC > 0 then call ExitMsg(THOR.LASTERROR) EditItem = result select when EditItem = '' then iterate when EditItem = 'Help' then do call ShowHelp iterate end when EditItem = 'Accept' then leave otherwise do do i = 1 to EditMenu.Count if EditMenu.i = EditItem then leave end ItemNo = i end end parse var EditItem EditTitle ':' EditValue EditValue = strip(EditValue,L) /* Call edit procedure for that field */ do i = 1 to Fields.Name.Count if EditTitle = Fields.Menu.i then do interpret 'call Edit'||Fields.Name.i interpret 'EditTemp.'||Fields.Name.i '= EditValue' Changed = 1 leave end end end /* Copy values back from temporary variable */ Config.CfgNo = EditTemp.Config do i = 2 to Fields.Name.Count interpret 'tmp = EditTemp.'Fields.Name.i if tmp > '' then interpret 'Config.CfgNo.'Fields.Name.i' = tmp' else interpret 'drop Config.CfgNo.'Fields.Name.i end return 0 ;; /* :Add a configuration */ AddCfg: EditValue = '' call EditCONFIG /* Get config name */ if EditValue = '' then return do i = 1 to Config.Count /* Check this name is not already used */ if upper(EditValue) = upper(Config.i) then do 'REQUESTNOTIFY "There is already a configuration item called 'Config.i'." bt " OK "' return end end CfgNo = Config.Count+1 Config.CfgNo = EditValue EditValue = '' call EditSYSTEM /* Get system */ if EditValue = '' then return Config.CfgNo.SYSTEM = EditValue EditValue = '' call EditCONFERENCE /* Conference */ if EditValue = '' then return Config.CfgNo.CONFERENCE = EditValue EditValue = '' call EditTEXTFILE /* Reply text */ if EditValue = '' then return Config.CfgNo.TEXTFILE = EditValue if EditCfg(CfgNo) = 0 then do /* Edit configuration */ Changed = 1 Config.Count = CfgNo end return ;; /* :Alter individual configuration items */ EditCONFIG: REQUESTSTRING title '"CfgAutoReply"' body '"Name of configuration item "' BT '" _OK |Cancel"' ID '"'EditValue'"' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditSYSTEM: address(bbsread) drop BBSS. GETBBSLIST stem BBSS if RC = 30 then call ExitMsg(BBSREAD.LASTERROR) address(thorport) REQUESTLIST instem BBSS title '"Name of system containing incoming messages "' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditCONFERENCE: address(bbsread) drop CONFS. GETCONFLIST bbsname '"'Config.CfgNo.System'"' stem CONFS if RC = 30 then call ExitMsg(BBSREAD.LASTERROR) address(thorport) REQUESTLIST instem CONFS title '"Name of conference containing incoming messages "' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditTEXTFILE: call SplitPath() REQUESTFILE title '"Please select the reply text file"' ID '"'path'"' IF '"'file'"' FULLPATH if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditSUBJECT: REQUESTSTRING title '"CfgAutoReply"' body '"Subject line for reply\nUse %%s to include original subject\nDefault is Re: %s"' BT '" _OK |Cancel"' ID '"'EditValue'"' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditQUOTEMSG: REQUESTNOTIFY '"Where would you like the quote the incoming mail,\n above your reply, below it, or not at all?"' '"_Above|_Below|_NoQuote"' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) select when result = 1 then EditValue = 'Above' when result = 2 then EditValue = 'Below' otherwise EditValue = '' end return EditQUOTESTR: REQUESTSTRING title '"CfgAutoReply"' body '"The string or character prepended to quoted lines"' BT '" _OK |Cancel"' ID '"'EditValue'"' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditSIGFILE: call SplitPath() REQUESTFILE title '"Please select signature file"' ID '"'path'"' IF '"'file'"' FULLPATH if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditHEADFILE: call SplitPath() REQUESTFILE title '"Please select a header file"' ID '"'path'"' IF '"'file'"' FULLPATH if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return EditFOOTFILE: call SplitPath() REQUESTFILE title '"Please select a footer file"' ID '"'path'"' IF '"'file'"' FULLPATH if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) EditValue = result return ;; /* :Split the current EditValue into path and file */ SplitPath: select when lastpos('/',EditValue) > 0 then do pathend = lastpos('/',EditValue) path = left(EditValue,pathend-1) file = substr(EditValue,pathend+1) end when lastpos(':',EditValue) > 0 then do pathend = lastpos(':',EditValue) path = left(EditValue,pathend) file = substr(EditValue,pathend+1) end when EditValue = '' then do Path = 'RAM:' File = '' end otherwise do path = '' file = EditValue end end return ;; /* :Delete a configuration */ DeleteCfg: /* Select config to delete */ REQUESTLIST instem Config title '"Choose configuration to delete "' if RC = 5 then return if RC > 0 then call ExitMsg(THOR.LASTERROR) DelCfg = result REQUESTNOTIFY '"'DelCfg||':\nAre you sure you want to delete this configuration?"' '"_Delete|_Cancel"' if result = 0 then return Changed = 1 do i = 1 to Config.Count if Config.i = DelCfg then leave end CfgNo = i Config.Count = Config.Count - 1 if CfgNo <= Config.Count then do i = CfgNo to Config.Count x = i+1 Config.i = Config.x do j = 1 to Fields.Name.Count if symbol('Config.x.'Fields.Name.j) = 'VAR' then do interpret 'Config.i.'Fields.Name.j '= Config.x.'Fields.Name.j end else do interpret 'drop Config.i.'Fields.Name.j end end end return ;; /* :Save the config to ENV: */ UseCfg: if exists(CfgFile) then address command 'copy >NIL:' CfgFile CfgFile'.bak' if ~open(cfg,CfgFile,'w') then call ExitMsg('Failed to open configuration file to save') /* Open progress window */ OPENPROGRESS title '"CfgAutoReply.thor"' PT '"Writing configuration"' if RC > 0 then call ExitMsg(THOR.LASTERROR) ProgWin = result do i = 1 to Config.Count call writeln(cfg,'CONFIG "'Config.i'"') do j = 2 to Fields.Name.Count if symbol('Config.i.'Fields.Name.j) ~= 'VAR' then iterate CfgName = left(Fields.Name.j||' ',13) interpret 'CfgVal = Config.i.'Fields.Name.j call writeln(cfg,CfgName'"'CfgVal'"') end call writeln(cfg,'ENDCONFIG') call writeln(cfg,'') /* Update progress bar */ UPDATEPROGRESS req ProgWin current i*100%Config.Count end call close(cfg) CLOSEPROGRESS req ProgWin Changed = 0 return ;; /* :Save the config to ENVARC: */ SaveCfg: call UseCfg() address command 'copy >NIL:' CfgFile'#? TO ENVARC:THOR' return ;; /* :Call multiview to display help file */ ShowHelp: drop GLOBALCFG. GETGLOBALCONFIG stem GLOBALCFG /* Get global information */ address command 'MultiView `GetEnv THOR/THORPath`docs/AutoReply.guide PUBSCREEN' GLOBALCFG.PUBSCREENNAME return ;;